Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SplitMode for SPM Package #232

Closed
wants to merge 1 commit into from
Closed

Conversation

mackoj
Copy link
Contributor

@mackoj mackoj commented Mar 26, 2020

This is another try at #225.

TL;DR

This change nothing to all actual users of Swaggen. It add the support of splitting the generated code for SPM user only and only if they want to. This is the first step to remove Alamofire. It allow to run generated code on Linux if you only use the request and model targets. And finally it add dynamic library support when using SPM.

What have been done

This PR is focus to mainly focus to split in SPM the generated code into 4 part:

  • Client: take an URLRequest and send them
  • Models: all the generated models and enums
  • Requests: all the generated request builders - this part generate URLRequest
  • SharedCode: Shared code between various targets
├── Client
│   ├── APIClient.swift
│   └── RequestBehaviour.swift
├── Models
│   ├── APIModel.swift
│   ├── AnyCodable.swift
│   ├── Coding.swift
│   ├── Enum.swift
│   └── Model.swift
├── Requests
│   ├── API.swift
│   ├── APIRequest.swift
│   ├── APIResponse.swift
│   ├── APIService.swift
│   ├── AnyRequest.swift
│   └── Request.swift
└── SharedCode
    ├── APIClientError.swift
    └── APIResult.swift
    └── Timeline.swift

Why

I did these changes because:

  • I needed to have a generated library working on Linux and Alamofire even the version 5 don't support Linux(WIP Linux Support Alamofire/Alamofire#3098)
  • Simplify the PR that will move Alamofire out
  • I needed to onboard new developper to SwagGen development
  • I needed the dynamic library support for a big project that I work on that use XcodeGen and some module are imported in multiple place so we needed the dynamic library linking in order to making it work

Remarks

I don't think this should be another template because it doesn’t change the main template it make it more flexible.

Point of interest to the reviewer

In order to make everything works I have to make createURLRequest but it worked with Alamofire so I needed to import the relevant part from Alamofire to make it work.
I did copy the Alamofire Timeline file in order to keep the feature.

Todo after review (in order to not clutter the main work of this PR)

  • we should add support for CI for Linux after this is merged.
  • adding test on podspec in CI could be great too.
  • updating fixtures

I hope it helps.

@mackoj mackoj force-pushed the RedoSplit branch 2 times, most recently from 8f2db94 to 9e31b07 Compare March 26, 2020 01:55
@mackoj mackoj marked this pull request as ready for review March 26, 2020 02:00
@mackoj mackoj force-pushed the RedoSplit branch 2 times, most recently from f8bbebb to bfba94d Compare March 30, 2020 10:04
@mackoj
Copy link
Contributor Author

mackoj commented Mar 30, 2020

Update from #230 modifications.

@mackoj
Copy link
Contributor Author

mackoj commented Mar 31, 2020

Rebase for #239

@mackoj mackoj closed this Mar 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant